package oss

import (
	"context"
	"github.com/minio/minio-go/v7"
	"github.com/minio/minio-go/v7/pkg/credentials"
	"mgs/config"
	"mime/multipart"
)

type Minio struct {
}

var minioClient *minio.Client
var defaultBucketName string

func InitMinio(cfg config.Config) {
	mf := cfg.Minio
	mc, err := minio.New(mf.Endpoint, &minio.Options{
		Creds:  credentials.NewStaticV4(mf.AccessKey, mf.SecretKey, ""),
		Secure: mf.Secure,
	})
	if err != nil {
		panic(err)
	}
	minioClient = mc
	defaultBucketName = mf.BucketName
}

// UploadFile 上传文件
func (*Minio) UploadFile(file *multipart.FileHeader) (string, string, error) {
	return "filename", "md5", nil
}

func (*Minio) FGetObject(key, infile string) error {
	return minioClient.FGetObject(context.Background(), defaultBucketName, key, infile, minio.GetObjectOptions{})
}

// DeleteFile 删除文件
func (*Minio) DeleteFile(key string) error {

	return nil
}
